import request from '../utils/request'

/**
 * 获取参数列表
 * @param {number} id 分类ID
 * @param {string} sel only为静态参数，many为动态参数
 * @returns promise
 */
export const getParamsAPI = (id, sel) => request({
    url: `categories/${id}/attributes`,
    params: {
        sel
    }
})

/**
 * 添加动态参数或者静态属性
 * @param {number} id 分类ID
 * @param {Object} data { attr_name: 参数名称, attr_sel: only or many, attr_vals: 如果是 many 就需要填写值的选项，以逗号分隔}
 * @returns promise
 */
export const addParamsAPI = (id, data) => request({
    method: 'post',
    url: `categories/${id}/attributes`,
    data
})

/**
 * 编辑提交参数
 * @param {number} id 分类ID
 * @param {number} attrId 属性ID
 * @param {Object} data {attr_name, attr_sel, attr_vals}
 * @returns promise
 */
export const editParamsAPI = (id, attrId, data) => request({
    method: 'put',
    url: `categories/${id}/attributes/${attrId}`,
    data
})

/**
 * 删除参数
 * @param {number} id 分类ID
 * @param {number} attrid 参数ID
 * @returns promise
 */
export const delParamsAPI = (id, attrid) => request({
    method: 'delete',
    url: `categories/${id}/attributes/${attrid}`
})